package com.deyuanyun.pic.insp.service.inspresult.impl;

import com.deyuanyun.pic.common.tool.JXL;
import com.deyuanyun.pic.insp.mapper.InspGwwMapper;
import com.deyuanyun.pic.insp.service.inspresult.InspGwwService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.github.pagehelper.Page;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class InspGwwServiceImpl extends BaseServiceImpl  implements InspGwwService {
	@Resource
	private InspGwwMapper inspgwwservice;

	@Override
	public Page<HashMap<String, Object>> getMain(HashMap<String, Object> map) {
		handlerParam(map);
		initPage();
		Page<HashMap<String, Object>> data=inspgwwservice.getMain(map);
		handlCeharacteristic(data,map);
		return data ;
	}

	@Override
	public Page<LinkedHashMap<String, Object>> findPage(HashMap param) {
		handlerParam(param);
		initPage();
		Page<LinkedHashMap<String, Object>> data=inspgwwservice.findPage(param);
		for(LinkedHashMap<String, Object> map:data)
		{
			map.put("REPAIR_SUGGESTION", CodeUtil.getName((String) map.get("REPAIR_SUGGESTION")));
		}
		return data;
	}

	@Override
	public Page<HashMap<String, Object>> getStatistics(HashMap<String, Object> map) {
		handlerParam(map);
		return inspgwwservice.getStatistics(map);
	}

	@Override
	public List queryExport(HashMap<String, Object> map) {
		handlerParam(map);
		List<LinkedHashMap<String,Object>> data=  inspgwwservice.queryExport(map);
		return data;
	}

	@Override
	public List<LinkedHashMap<String, Object>> exportAll(HashMap<String, Object> map) {
		handlerParam(map);
		StringBuilder where =new StringBuilder();
		where.append(" DELETED = 0 and VSERSION=1 ");
		where.append(" and PIPE_LINE_ID='").append(map.get("lineId")).append("'");
		where.append(" and INSP_TASK_ID='").append(map.get("taskId")).append("'");
		StringBuilder where1 =new StringBuilder(where);

		if(map.get("beginMileage") != null)
		{
			where.append(" and MILEAGE >=").append(map.get("beginMileage"));
			where1.append(" and FROM_MILEAGE >=").append(map.get("beginMileage"));
		}
		if(map.get("endMileage") != null)
		{
			where.append(" and MILEAGE <").append(map.get("endMileage"));
			where1.append(" and FROM_MILEAGE <").append(map.get("endMileage"));
		}
		map.put("where",where.toString());
		map.put("where2",where1.toString());

		return inspgwwservice.exportAll(map);
	}


	public Long exportAllCount(HashMap<String, Object> map){
		handlerParam(map);
		StringBuilder where =new StringBuilder();
		where.append(" DELETED = 0 and VSERSION=1 ");
		where.append(" and PIPE_LINE_ID='").append(map.get("lineId")).append("'");
		where.append(" and INSP_TASK_ID='").append(map.get("taskId")).append("'");
		StringBuilder where1 =new StringBuilder(where);

		if(map.get("beginMileage") != null)
		{
			where.append(" and MILEAGE >=").append(map.get("beginMileage"));
			where1.append(" and FROM_MILEAGE >=").append(map.get("beginMileage"));
		}
		if(map.get("endMileage") != null)
		{
			where.append(" and MILEAGE <").append(map.get("endMileage"));
			where1.append(" and FROM_MILEAGE <").append(map.get("endMileage"));
		}
		map.put("where",where.toString());
		map.put("where2",where1.toString());

		return inspgwwservice.exportAllCount(map);
	}
}
